<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <form>
        <div>
            账号:
            <input type="text" id="loginId" name="loginId" placeholder="请输入账号">
        </div>
        <div>
            密码:
            <input type="password" id="loginPwd" name="loginPwd" placeholder="请输入密码">
        </div>
        <div>
            验证码:
            <input type="text" id="captcha" name="captcha">
            <img src="/res/captcha" alt="">
        </div>
        <button type="button">登录</button>
    </form>
    <script>
        const loginId = document.querySelector("#loginId");
        const loginPwd = document.querySelector("#loginPwd");
        const captcha = document.querySelector("#captcha");
        const img = document.querySelector("img");
        img.onclick = function () {
            fetch("http://localhost:9527/res/captcha").then(res => {
                img.src = res.url;
            })
        }
        document.querySelector("button").onclick = function () {
            const data = {
                loginId: loginId.value,
                loginPwd: loginPwd.value,
                captcha: captcha.value,
                remember: 7
            }
            img.src = "/res/captcha?" + Math.random();
            fetch("http://localhost:9527/api/admin/login", {
                method: "POST",
                headers: {
                    "content-type": "application/json"
                },
                body: JSON.stringify(data)
            }).then(res => res.json()).then(res => {
                console.log(res);
            })

        }
    </script>
</body>

</html>